class Solution {
public:
    bool containsNearbyDuplicate(vector<int>& nums, int k) {
        map<int, int> dp;
        for (int cur = 0; cur < nums.size(); cur++)
        {
            if (dp.count(nums[cur]))
                if (cur - dp[nums[cur]] <= k) return true;
            dp[nums[cur]] = cur;
        }
        return false;
    }
};
class Solution {
public:
    vector<vector<string>> groupAnagrams(vector<string>& strs) {
        map<string, vector<string>> dp;
        for (auto& num : strs)
        {
            string s = num;
            std::sort(s.begin(), s.end());
            dp[s].push_back(num);
        }
        vector<vector<string>> v;
        for (auto& [x, y] : dp)
        {
            v.push_back(y);
        }
        return v;
    }
};
